package com.ruoyi.web.controller.applet.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.ClassType;
import com.ruoyi.common.enums.YesOrNo;
import com.ruoyi.system.domain.SysAppArticle;
import com.ruoyi.system.domain.SysAppBanner;
import com.ruoyi.system.domain.SysAppBookinfo;
import com.ruoyi.system.domain.SysAppClassification;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysAppArticleService;
import com.ruoyi.system.service.ISysAppBannerService;
import com.ruoyi.system.service.ISysAppBookinfoService;
import com.ruoyi.system.service.ISysAppClassificationService;
import com.ruoyi.system.service.ISysNoticeService;

@Controller
@RequestMapping("/applet/index")
public class IndexController extends BaseController {

	@Autowired
	private ISysAppBannerService sysAppBannerService;

	@Autowired
	private ISysAppClassificationService sysAppClassificationService;

	@Autowired
	private ISysAppBookinfoService sysAppBookinfoService;

	@Autowired
	private ISysAppArticleService sysAppArticleService;

	@Autowired
	private ISysNoticeService noticeService;

	/**
	 * 首页加载
	 * 
	 * @return
	 */
	@PostMapping("/home")
	@ResponseBody
	public AjaxResult home() {
		Map<String, Object> map = Maps.newConcurrentMap();
		/* 1、轮播图获取 */
		SysAppBanner banner = new SysAppBanner();
		banner.setIsEnable(YesOrNo.yes.getInfo());
		List<SysAppBanner> appBanners = sysAppBannerService.selectSysAppBannerList(banner);
		/* 2、获取首页分类 */
		SysAppClassification appClassification = new SysAppClassification();
		appClassification.setClassType(ClassType.home.getInfo());
		List<SysAppClassification> classifications = sysAppClassificationService
				.selectSysAppClassificationList(appClassification);
		/* 3、获取热门书籍 */
		SysAppBookinfo bookInfo = new SysAppBookinfo();
		bookInfo.setBookType(1);
		bookInfo.setBookStatus(YesOrNo.yes.getInfo());
		List<SysAppBookinfo> bookinfos = sysAppBookinfoService.selectSysAppBookinfoList(bookInfo);
		/* 4、获取经典文章 */
		SysAppArticle article = new SysAppArticle();
		article.setState(YesOrNo.yes.getInfo());
		article.setNoticeType("1");
		List<SysAppArticle> articles = sysAppArticleService.selectSysAppArticleList(article);
		/* 获取通知列表 */
		SysNotice notice = new SysNotice();
		notice.setNoticeType("1");
		notice.setStatus("0");
		List<SysNotice> list = noticeService.selectNoticeList(notice);
		map.put("banners", appBanners);
		map.put("classification", classifications);
		map.put("bookinfos", bookinfos);
		map.put("articles", articles);
		map.put("hanchuanTeams", list);
		return AjaxResult.success("操作成功", map);
	}

}
